package com.wsx.ones.gateway.server.config;

import com.wsx.ones.gateway.common.ConfigManager;
import com.wsx.ones.gateway.core.config.RouterConfig;
import com.wsx.ones.gateway.remote.netty.NettyServerConfig;
import com.wsx.ones.gateway.server.GatewayConfig;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;

/**
 * @author wangshuaixin
 * @Title: com.wsx.ones.gateway.server.config.GatewayManager
 * @Description: TODO
 * @date 2019/07/20
 */
public class GatewayManager extends ConfigManager {

    private static final Logger log = LogManager.getLogger(GatewayManager.class);

    @Setter @Getter
    private String fileName = "gateway.yml";

    @Setter @Getter
    private Gateway gateway;

    @Override
    public String configFilePath() {
        return this.getClass().getClassLoader().getResource(fileName).getFile();
    }

    @Override
    public void decode(String file) {
        Gateway config = null;
        try {
            config = new Yaml().loadAs(new FileInputStream(file), Gateway.class);
        } catch (Exception e) {
            log.error("yaml decode error", e);
        }
        if (null != config) {
            setGateway(config);
        }
    }

    public void processGatewayConfig(GatewayConfig gatewayConfig) {

    }

    public void processNettyServerConfig(NettyServerConfig nettyServerConfig) {

    }

    public void processRouterConfig(RouterConfig routerConfig) {

    }
}
